/**
 * Copyright (c) 2007,中企动力华南研发中心<br>
 * All rights reserved.<br>
 */
package com.ce.pms.system.renovation.web;

import java.util.List;

import com.ce.pms.base.vo.SearchVO;
import com.ce.pms.base.web.PmsBaseAction;
import com.ce.pms.charge.service.IBusinessCodeService;
import com.ce.pms.charge.vo.BusinessCodeVO;
import com.ce.pms.exception.BusinessException;
import com.ce.pms.exception.UILayerException;
import com.ce.pms.system.renovation.service.IPassChargeItemConfigService;
import com.ce.pms.system.renovation.vo.PassChargeItemConfigVO;
import com.sitechasia.webx.core.annotation.Read;
import com.sitechasia.webx.core.support.Page;

/**
 * 功能描述：<br>
 * @author 易贤建 创建日期：2008-12-24<br>
 */
public class InAndOutAction extends PmsBaseAction {
	/**
	 * 交易码Service
	 */
	private IBusinessCodeService businessCodeService = null;

	private IPassChargeItemConfigService passChargeItemConfigService = null;

	/**
	 * 功能描述:初始化列表页面<br>
	 * @param searchVO
	 * @param pageSize
	 * @param pageNo
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-30  <br>
	 */
	public String initList(@Read SearchVO searchVO,
						   @Read(key = "ec_crd",defaultValue="10")	int pageSize,
			               @Read(key = "ec_p", defaultValue="1")	int pageNo){
		searchVO.setPageSize(pageSize);
		searchVO.setPageNo(pageNo);

		Page page = passChargeItemConfigService.queryPassChargeItemConfigList(searchVO);
		setAttribute("passchargeItemConfigs", page.getResult());
		setAttribute("totalRows", Integer.valueOf(String.valueOf(page.getTotalCount())));
		return "list";
	}
	/**
	 * 功能描述:初始化添加页面<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-31  <br>
	 */
	public String initAdd(){
		initBusinessCode();
		return "add";
	}
	/**
	 * 功能描述:功能描述:初始化修改页面<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-31  <br>
	 */
	public String initEdit(@Read(key="keyword")Long keyword){
		PassChargeItemConfigVO configVO = passChargeItemConfigService.findById(keyword);
		setAttribute("configVO", configVO);
		initBusinessCode();
		return "edit";
	}
	/**
	 * 功能描述:添加<br>
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-31  <br>
	 */
	public String add(@Read PassChargeItemConfigVO configVO){
		configVO.setCreator(super.getUserId());
		//如果入账方式为空,就设置为直接入账
		if(configVO.getEnterAccountMethod() == null)
			configVO.setEnterAccountMethod("001");
		passChargeItemConfigService.add(configVO);
		processOption(); //处理按钮类型
		return "result";
	}
	/**
	 * 功能描述:修改<br>
	 * @param configVO
	 * @return
	 * Create author:yixianjian <br>
	 * Create on:2008-12-31  <br>
	 */
	public String edit(@Read PassChargeItemConfigVO configVO){
		configVO.setModifier(super.getUserId());
		//如果入账方式为空,就设置为直接入账
		if(configVO.getEnterAccountMethod() == null)
			configVO.setEnterAccountMethod("001");
		passChargeItemConfigService.edit(configVO);
		processOption(); //处理按钮类型
		return "result";
	}
	/**
	 * 功能描述:删除<br>
	 * @param keyword
	 * Create author:yixianjian <br>
	 * Create on:2008-12-31  <br>
	 */
	public void delete(@Read(key="keyword")Long keyword){
		try{
			passChargeItemConfigService.delete(keyword);
		}catch(BusinessException exception){
			throw exception;
		}catch(Exception exception){
			throw new UILayerException("system:approval_delete_is_reference");
		}
	}
	/**
	 * 功能描述:验证收费项目名称的唯一性<br>
	 * @param configVO
	 * Create author:yixianjian <br>
	 * Create on:2009-1-4  <br>
	 */
	public void validateItemName(@Read PassChargeItemConfigVO configVO){
		try{
			passChargeItemConfigService.validateItemName(configVO);
			super.renderText("true");
		}catch(BusinessException exception){
			String errorMessage = exception.getMessage();
			super.renderText(super.getLocaleMessage(errorMessage));
		}
	}
	/**
	 * 功能描述: 处理页面传过来的按钮类型,页面有保存并新增、保存按钮,页面有按钮类型隐藏表单域<br>
	 * Create author:yixianjian <br>
	 * Create on:2008-12-30  <br>
	 */
	private void processOption(){
		String option = getRequest().getParameter("option");
		setAttribute("option", option);
	}
	/**
	 * 功能描述:缓存收入类型的交易码列表<br>
	 * Create author:yixianjian <br>
	 * Create on:2008-12-30  <br>
	 */
	private void initBusinessCode(){
		List<BusinessCodeVO> bizCode  = passChargeItemConfigService.getBusinessCodeList();
		setAttribute("bizCodes", bizCode);
	}
	public void setBusinessCodeService(IBusinessCodeService businessCodeService) {
		this.businessCodeService = businessCodeService;
	}
	public void setPassChargeItemConfigService(
			IPassChargeItemConfigService passChargeItemConfigService) {
		this.passChargeItemConfigService = passChargeItemConfigService;
	}
}
